package com.zoweunion.mechanic.controller;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.zoweunion.mechanic.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.service.TSSsVehicleTypeService;
import com.zoweunion.mechanic.entity.TSSsVehicleTypeEntity;


import com.zoweunion.mechanic.model.ResponseBean;
import com.github.pagehelper.PageInfo;

import javax.servlet.http.HttpServletRequest;


/**
 * 车类
 *
 * @author xp
 * @email 17688825585@163.com
 * @date 2020-05-25 19:02:35
 */
@RestController
@RequestMapping("/tsssvehicletype")
public class TSSsVehicleTypeController extends BaseController {
    @Autowired
    private TSSsVehicleTypeService tSSsVehicleTypeService;

    /**
     * 列表
     */
    @GetMapping("/tSSsVehicleTypeList")
    public ResponseBean tSSsVehicleTypeList(@RequestParam Map<String, Object> params, HttpServletRequest request) throws MyException {
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        PageInfo info = tSSsVehicleTypeService.queryPage(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }

    /**
     * 新增
     */
    @PostMapping("/tSSsVehicleTypeInsertUpdate")
    public ResponseBean tSSsVehicleTypeInsertUpdate(@RequestBody TSSsVehicleTypeEntity params,
                                                    HttpServletRequest request) {
        if (params.getId() != null) {
            tSSsVehicleTypeService.updateById(params);
        } else {
            params.setId(UuidUtil.get32UUID());
            tSSsVehicleTypeService.save(params);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 列表
     */
    @GetMapping("/tSSsVehicleTypeListFor")
    public ResponseBean tSSsVehicleTypeListFor(@RequestParam Map<String, Object> params, HttpServletRequest request) throws MyException {
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        List<TSSsVehicleTypeEntity> list = tSSsVehicleTypeService.tSSsVehicleTypeListFor(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", list);
    }


}
